import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import { docsBase } from '../docs/.vuepress/buildConfig'

const routes: RouteConfig[] = [
  {
    path: '/',
    redirect: '/widget/status'
  },
  {
    path: '/contract/view',
    component: () => import('./views/ContractView.vue'),
    meta: {
      title: '文档查看'
    }
  },
  {
    path: '/widget/status',
    component: () => import('./views/WidgetStatus.vue'),
    meta: {
      title: '控件状态'
    }
  },
  {
    path: '/widget/set',
    component: () => import('./views/WidgetSet.vue'),
    meta: {
      title: '控件设置'
    }
  },
  {
    path: '/contract/sign',
    component: () => import('./views/ContractSign.vue'),
    meta: {
      title: '合同签署'
    }
  },
  {
    path: '/contract/fill',
    component: () => import('./views/ContractFill.vue'),
    meta: {
      title: '合同填写'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: !!import.meta.env.DEV ? '/' : `${docsBase}demo/`,
  routes
})

router.afterEach(to => {
  const customTitle = to.meta?.title as string
  const defaultTitle = 'FddContract'
  document.title = customTitle ? `${customTitle} | ${defaultTitle}` : defaultTitle
})

Vue.use(VueRouter)

export default router
